home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT33.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.0 KB  |  77 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 33                         
  5.                                                                               
  6.  Demonstrates the use of wbezier. Draws random curves until key pressed.     
  7.                                                                               
  8.  *** PROJECT ***                                                             
  9.  This program requires the file WGT5_WC.LIB to be linked.                    
  10.                                                                               
  11.  *** DATA FILES ***                                                          
  12.  NONE                                                                        
  13.                                                            WATCOM C++ VERSION 
  14. ==============================================================================
  15. */
  16.  
  17. #include <stdlib.h>
  18. #include <wgt5.h>
  19.  
  20. #define NUM_IN 5       /* number of random points */
  21. #define NUM_OUT 30     /* number of points of bezier curve */
  22. /* Fewer points will make more chunky line */
  23.  
  24. void main (void)
  25. {
  26.   tpolypoint inpoint[NUM_IN];   /* Array with the normal curve points */
  27.   tpolypoint outpoint[NUM_OUT]; /* Array with smooth curve points */
  28.   block other;                  /* Pointer to our second screen */
  29.   short i;                        /* Loop counter */
  30.   short oldmode;                  /* Stores initial video mode */
  31.  
  32.   if ( !vgadetected () )
  33.   {
  34.     printf("Error - VGA card required for any WGT program.\n");
  35.     exit (0);
  36.   }
  37.  
  38.   printf ("WGT Example #33\n\n");
  39.   printf ("Random bezier curves are drawn until a key is pressed.\n");
  40.   printf ("\n\nPress any key to continue.\n");
  41.   getch ();
  42.  
  43.   oldmode = wgetmode ();         /* Gets the current mode */
  44.   vga256 ();                     /* Initialize graphics mode */
  45.  
  46.   other = wnewblock (0, 0, 319, 199);    /* Allocate second screen */
  47.  
  48.   wsetcolor (15);                        /* Draw with white */
  49.  
  50.   do {
  51.     wsetscreen (other);                  /* We'll draw on the hidden screen */
  52.     wcls (0);                            /* Clear it with black */
  53.  
  54.     for (i = 0; i < NUM_IN; i++)         /* Randomize the BEZIER control pts */
  55.     {
  56.       inpoint[i].x = rand () % 320;
  57.       inpoint[i].y = rand () % 200;
  58.     }
  59.  
  60.     wbezier (inpoint, NUM_IN, outpoint, NUM_OUT);   /* Generate line */
  61.  
  62.     whollowpoly (outpoint, NUM_OUT, 0, 0, OPEN_POLY);
  63.     /* draw the smooth curve */
  64.  
  65.     wnormscreen ();                 /* Reset drawing to visual screen */
  66.     wputblock (0, 0, other, 0);     /* Show the screen */
  67.   } while (!kbhit ());              /* Abort if key pressed */
  68.   getch ();                         /* Get the key */
  69.  
  70.   wfreeblock (other);            /* Free our screen buffer */
  71.   wsetmode (oldmode);            /* Restore initial video mode */
  72. }
  73.  
  74.  
  75.  
  76.  
  77.